﻿using System.Collections.Generic;
using System.Web.Services;
using Newtonsoft.Json;
using NPSoft.Ferrero.DataBridge.BLL;
using NPSoft.Ferrero.DataBridge.Model;
using NPSoft.Ferrero.Framework.BLL;
using NPSoft.Ferrero.Framework.Web;

namespace NPSoft.Ferrero.DataBridge.Web.Services
{
    /// <summary>
    /// FerreroChinaOutBoundService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    [System.Web.Script.Services.ScriptService]
    public class FerreroChinaToJsonService : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetDistributor()
        {
            IBLL<Distributor> bllDist = NPWebApp.Container.Resolve<IBLL<Distributor>>();
            ICollection<Distributor> dists = bllDist.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(dists);
        }

        [WebMethod]
        public string GetHumanResource()
        {
            IBLL<HumanResource> bllHum = NPWebApp.Container.Resolve<IBLL<HumanResource>>();
            ICollection<HumanResource> human = bllHum.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(human);
        }

        [WebMethod]
        public string GetGeography()
        {
            IBLL<Geography> bllGeo = NPWebApp.Container.Resolve<IBLL<Geography>>();
            ICollection<Geography> geog = bllGeo.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(geog);
        }

        [WebMethod]
        public string GetStore()
        {
            IBLL<Store> bllSto = NPWebApp.Container.Resolve<IBLL<Store>>();
            ICollection<Store> store = bllSto.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(store);
        }

        [WebMethod]
        public string GetBanner()
        {
            IBLL<Banner> bllBan = NPWebApp.Container.Resolve<IBLL<Banner>>();
            ICollection<Banner> banner = bllBan.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(banner);
        }

        [WebMethod]
        public string GetProductCTPrice()
        {
            IBLL<ProductCTPrice> bllProCT = NPWebApp.Container.Resolve<IBLL<ProductCTPrice>>();
            ICollection<ProductCTPrice> proCT = bllProCT.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(proCT);
        }

        [WebMethod]
        public string GetProduct()
        {
            IBLL<Product> bllPro = NPWebApp.Container.Resolve<IBLL<Product>>();
            ICollection<Product> product = bllPro.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(product);
        }

        [WebMethod]
        public string GetProductUOM()
        {
            IBLL<ProductUOM> bllProUOM = NPWebApp.Container.Resolve<IBLL<ProductUOM>>();
            ICollection<ProductUOM> proUOM = bllProUOM.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(proUOM);
        }

        [WebMethod]
        public string GetProductRTPrice()
        {
            IBLL<ProductRTPrice> bllProRT = NPWebApp.Container.Resolve<IBLL<ProductRTPrice>>();
            ICollection<ProductRTPrice> proRT = bllProRT.Search(new System.Text.StringBuilder());

            return JsonConvert.SerializeObject(proRT);
        }

        [WebMethod]
        public string GetData(string Type)
        {
            switch(Type)
            {

                case "001": GetDistributor();
                    break;

                case "002": GetHumanResource();
                    break;

                case "003": GetGeography();
                    break;

                case "004": GetStore();
                    break;

                case "005": GetBanner();
                    break;

                case "006": GetProductCTPrice();
                    break;

                case "007": GetProduct();
                    break;

                case "008": GetProductUOM();
                    break;

                case "009": GetProductRTPrice();
                    break;

                default: 
                    break;
            }

            return JsonConvert.SerializeObject(Type);
        }
    }
}
